﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient; 

namespace WindowsFormsApp_i1
{
    public class SQL
    {
        public static int i = 0;
        static string connectString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\C#\WindowsFormsApp_i1\wordsRecite.mdf;Integrated Security=True;Connect Timeout=30";
        public static SqlConnection GetConnection()
        {
            SqlConnection connection = new SqlConnection(connectString);
            connection.Open();
            return connection;
        }
        public static void AddWords(int id, string english, string chinese)
        {
            string id1 = id.ToString();
            using (SqlConnection connection = GetConnection())
            {
                using (SqlCommand cmd = new SqlCommand
                   ("INSERT INTO [dbo].[Table] VALUES("+"'"+id+"',"+"'"+ chinese+"',"+"'"+ english+"')", connection))
                {
                    cmd.ExecuteNonQuery();
                }
            }
        }
        public static string GetNext()
        {
           
            using (SqlConnection connection = GetConnection())
            {
                using (SqlCommand cmd = new SqlCommand
                   ("SELECT chinese FROM [dbo].[Table] WHERE Id=" + ++i, connection))
                {
                       return (string)cmd.ExecuteScalar();
                }
            }
        }
        public static string GetEnglish()
        {
            using (SqlConnection connection = GetConnection())
            {
                using (SqlCommand cmd = new SqlCommand
                   ("SELECT english FROM [dbo].[Table] WHERE Id=" + i, connection))
                {
                    return (string)cmd.ExecuteScalar();
                }
            }
        }
    }
}
